@model RecurringPaymentSearchModel

@{
    //page title
    ViewBag.PageTitle = T("Admin.RecurringPayments").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Recurring payments");
}

<div class="content-header clearfix">
    <h1 class="pull-left">
        @T("Admin.RecurringPayments")
    </h1>
    <div class="pull-right">
        &nbsp;
        @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.ReccuringPaymentListButtons })
    </div>
</div>

<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            <div class="panel panel-default">
                <div class="panel-body">
                    <p>
                        @T("Admin.RecurringPayments.Description")
                    </p>
                    @await Html.PartialAsync("Table", new DataTablesModel
                    {
                        Name = "recurringpayments-grid",
                        UrlRead = new DataUrl("List", "RecurringPayment", null),
                        Length = Model.PageSize,
                        LengthMenu = Model.AvailablePageSizes,
                        ColumnCollection = new List<ColumnProperty>
                        {
                            new ColumnProperty(nameof(RecurringPaymentModel.Id))
                            {
                                Title = T("Admin.RecurringPayments.Fields.ID").Text,
                                Width = "50"
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.CustomerId))
                            {
                                Title = T("Admin.RecurringPayments.Fields.Customer").Text,
                                Width = "200",
                                Render = new RenderCustom("renderColumnCustomerInfo")
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.CycleLength))
                            {
                                Title = T("Admin.RecurringPayments.Fields.CycleLength").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.CyclePeriodStr))
                            {
                                Title = T("Admin.RecurringPayments.Fields.CyclePeriod").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.IsActive))
                            {
                                Title = T("Admin.RecurringPayments.Fields.IsActive").Text,
                                Width = "200",
                                ClassName = NopColumnClassDefaults.CenterAll,
                                Render = new RenderBoolean()
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.StartDate))
                            {
                                Title = T("Admin.RecurringPayments.Fields.StartDate").Text,
                                Width = "200"
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.NextPaymentDate))
                            {
                                Title = T("Admin.RecurringPayments.Fields.NextPaymentDate").Text,
                                Width = "200"
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.TotalCycles))
                            {
                                Title = T("Admin.RecurringPayments.Fields.TotalCycles").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.CyclesRemaining))
                            {
                                Title = T("Admin.RecurringPayments.Fields.CyclesRemaining").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(RecurringPaymentModel.Id))
                            {
                                Title = T("Admin.Common.Edit").Text,
                                Width = "100",
                                ClassName = NopColumnClassDefaults.Button,
                                Render = new RenderButtonEdit(new DataUrl("Edit"))
                            }
                        }
                    })
                    
                    <script>
                        function renderColumnCustomerInfo(data, type, row, meta) {
                            var textRenderer = $.fn.dataTable.render.text().display;
                            return '<a href="@Url.Content("~/Admin/Customer/Edit/")' + row.CustomerId + '">' + textRenderer(row.CustomerEmail) + '</a>';
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>